package com.fwmagic.flink.projectcase.queryactivitycase;

import com.fwmagic.flink.projectcase.queryactivitycase.async.AsyncQueryMysqlFunction;
import org.apache.flink.streaming.api.datastream.AsyncDataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.concurrent.TimeUnit;

/**
 * 异步查询Mysql
 */
public class AsyncQueryFromMysqlApplication {
    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> streamSource = env.socketTextStream("localhost", 8888);
        SingleOutputStreamOperator<String> result = AsyncDataStream.unorderedWait(streamSource, new AsyncQueryMysqlFunction(), 1000, TimeUnit.MILLISECONDS, 10);
        result.print();
        env.execute("AsyncQueryFromMysqlApplication");
    }
}
